Repository navigation
refactor(filter): hold the state of one parse in a FilterParseScope - #222
Merged
Merged
Conversation
ParseFilter kept its per-parse state in five thread-static fields in two files. It saved, set, and restored each field by hand. The state now lives in one FilterParseScope object. A nested parse on the same thread gets its own scope, and the outer scope comes back when the nested parse ends. The public API and the parse results do not change. A new test pins that a parse inside a parse keeps the settings of the outer parse.
Owner
Author
|
review-gate: passed 949719e The independent review found no high or medium findings. It found four low findings:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The state of one
ParseFiltercall was an implicit state machine. Five[ThreadStatic]fields in two files held it, andParseFiltersaved, set, and restored each field by hand. This PR puts that state in one place and changes no behavior.What changed
FilterParseScopeholds the parameter flag, the nesting limit and depth, and the two flags of the v1.14.2 retry. One[ThreadStatic]holds the current scope, andDisposegives back the outer scope.ParseFilteropens the scope withusing. The retry filter reads its own scope object, not the thread field.QueryNameHidUnknownIdentifierandRetryingForLegacyException.FilterValue.Parameterizewas an internal property with a setter. It is now a private getter that reads the scope.NestedParseTestspins that a parse inside a parse keeps the settings of the outer parse.Blast Radius
The public API, the parse results, and the exception types do not change.
FilterValueis internal, andInternalsVisibleTonames onlyQueryKit.UnitTests. Each parse now allocates one small object.The change fixes no bug. Before this change, the outer retry filter could read the flag of a nested parse that failed. By analysis and by a manual run on both builds, that case gave the same exception, so this PR has no behavior change to call out.
Verification
dotnet test QueryKit.UnitTests/passes 881 tests on net10.0 and net11.0.dotnet test QueryKit.IntegrationTests/passes 396 tests on Postgres. The Release build has no warnings.maintoo, because it pins behavior that already existed. A mutation that removes the restore inDisposemakes it fail withExpected name.HolderTypes {empty} to contain QueryKit.FilterValue1[System.String]`.verify-querykitdrives (parameterized values, nesting limit pass and fail, derived properties, a default filter) gave byte-identical JSON onmainand on this branch, against memory and Postgres.QueryKit.Net6Testslocally, because the .NET 6 runtime is not installed.